import {$} from "./ajax.js";
let userlist={
    register:function(value1,value2,value3){
     var p=new Promise(function(resolve,reject){
          $.get({url:"register.php",
                data:{name:value1,
                        pwd:value2,
                        phone:value3},
                dataType:"json",
                callback:function(e){
                    resolve(e)
                }
        })
     })  
     return p
    },
    login:function(value1,value2){
       var p=new Promise(function(resolve,reject){
           $.ajax({url:"login.php",
                   data:{name:value1,
                         pwd:value2},
                   dataType:"json",
                   callback:function(e){
                      resolve(e)
                   }     
                  })
       })
       return p 
    },
    showdate:function(con,order,type){
        var p=new Promise(function(resolve,reject){
            $.ajax({url:"index.php",
                   data:{con:con,
                         order:order,
                         type:type},
                   dataType:"json",
                   callback:function(e){
                      resolve(e)
                   }     
                  })
        })
        return p
    },
    del:function(id){
        var p=new Promise(function(resolve,reject){
            $.get({
                url:"delete.php",
                type:"get",
                dataType:"json",
                data:{
                    id:id
                },
                callback:function(e){
                  resolve(e)
                }
            })
        })
        return p
    },
    edit:function(id){
        var p=new Promise(function(resolve,reject){
            $.get({
                url:"getuserinfobyid.php",
                type:"get",
                dataType:"json",
                data:{
                    id:id
                },
                callback:function(e){
                  resolve(e)
                }
            })
        })
        return p 
    },
    updateuserinfo:function(user_name,user_pwd,user_phone,id){
        var p=new Promise(function(resolve,reject){
            $.get({
                url:"updateuserinfo.php",
                type:"get",
                dataType:"json",
                data:{
                    user_name:user_name,
                    user_pwd:user_pwd,
                    user_phone:user_phone,
                    id:id
                },
                callback:function(e){
                  resolve(e)
                }
            })
        })
        return p
    },
    isExituserName:function(userName){
        var p=new Promise(function(resolve,reject){
            $.get({
                url:"isExituserName.php",
                type:"get",
                dataType:"json",
                data:{
                    user_name:userName
                },
                callback:function(e){
                  resolve(e)
                }
            })
        })
        return p 
    },
    isExituserPhone:function(userPhone){
        var p=new Promise(function(resolve,reject){
            $.get({
                url:"isExituserPhone.php",
                type:"get",
                dataType:"json",
                data:{
                    user_phone:userPhone
                },
                callback:function(e){
                  resolve(e)
                }
            })
        })
        return p  
    }
}
let register=userlist.register;
let login=userlist.login;
let showdate=userlist.showdate;
let del=userlist.del;
let edit=userlist.edit;
let updateuserinfo=userlist.updateuserinfo;
let isExituserName=userlist.isExituserName;
let isExituserPhone=userlist.isExituserPhone;
export{register,login,showdate,del,edit,updateuserinfo,isExituserName,isExituserPhone};
